package adv7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.*;

public class MyServer {
	public static void main(String[] args) {

		try {
			ServerSocket st = new ServerSocket(6666);
			System.out.println("服务器启动成了。。。");
			while (true) {
				Socket s = st.accept();
				System.out.println("客户端连接了，信息是：" + s.getInetAddress() + "," + s.getPort() + "," + s.getLocalPort());

				InputStream in = s.getInputStream();
				OutputStream out = s.getOutputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(in));
				PrintWriter pw = new PrintWriter(out, true);// 第二个参数，自动刷新
				String str = null;
				while ((str = br.readLine()) != null) {
					System.out.println("client say:" + str);
					pw.println("你说的事：" + str + ",朕知道了。。。");
					// pw.flush();
				}
				s.close();
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	}
}
